namespace ASPNET.StarterKit.IssueTracker
{
    using ASPNET.StarterKit.IssueTracker.BusinessLogicLayer;
    using System;
    using System.Diagnostics;
    using System.Web.UI;

    public class DownloadAttachment : Page
    {
        private object designerPlaceholderDeclaration;

        public DownloadAttachment()
        {
            base.Load += new EventHandler(this.Page_Load);
            base.Init += new EventHandler(this.Page_Init);
        }

        [DebuggerStepThrough]
        private void InitializeComponent()
        {
        }

        private void Page_Init(object sender, EventArgs e)
        {
            this.InitializeComponent();
        }

        private void Page_Load(object sender, EventArgs e)
        {
            IssueAttachment attachment = IssueAttachment.GetIssueAttachmentById(int.Parse(this.Request.QueryString["id"]));
            this.Server.ScriptTimeout = 600;
            this.Response.Buffer = true;
            this.Response.Clear();
            this.Response.ContentType = "application/octet-stream";
            this.Response.AddHeader("Content-Disposition", "attachment; filename=\"" + attachment.FileName + "\";");
            this.Response.AddHeader("Content-Length", attachment.Attachment.Length.ToString());
            this.Response.BinaryWrite(attachment.Attachment);
            this.Context.Response.End();
        }
    }
}

